 /*-----------------------------------------------File Info------------------------------------------------
** File Name:               userConfig.h  
** Last modified date:      2016.09.8
** Last version:            V0.1
** Description:             
**
**--------------------------------------------------------------------------------------------------------            
** Created date:            2016.09.8
** author:                  YLY
** Version:                 V0.1
** Descriptions:            应用程序配置
**--------------------------------------------------------------------------------------------------------*/

#ifndef __CONFIG_H_
#define __CONFIG_H_

#include <stdio.h>

#include "osTypedef.h"
#include "osInclude.h"

#include "bspConfig.h"
#include "bspFMC.h"
#include "bspUART.h"
#include "bspSPI.h"
#include "bspI2C.h"
#include "bspADC.h"
#include "bspTimer.h"


#define DBG_CLOSE			0
#define DBG_ERR				1
#define DBG_DBG				2
#define GLOBAL_DBG_LEVEL	DBG_DBG

#if GLOBAL_DBG_LEVEL == DBG_DBG
	#define GLOBAL_DBG	printf
	#define GLOBAL_ERR	printf	
#elif GLOBAL_DBG_LEVEL == DBG_ERR
	#define GLOBAL_ERR	printf
#else
	#define GLOBAL_DBG(...)	
	#define GLOBAL_ERR(...)	
#endif

#define RC4_MCU_KEY	"QGZL"
#define RC4_MCU_KEY_LEN	strlen(RC4_MCU_KEY)

/*  版本号 */
#define   PROGRAM_VER_ARCH			0U		/* 默认AP程序版本号 */
#define   PROGRAM_VER_SOFT			0U
#define   PROGRAM_VER_MODIFY		1U

/* 升级渠道
*  RV1109   MCU_DITCH_“IDENTIFIER”
*/
#define   IDENTIFIER				3U		/* AP程序渠道号,升级类型（渠道号）为"MCU_DITCH_+IDENTIFIER",M058门口机为0,GDE230为3,M058门禁机为1*/

#define   RUNNING_ENV_APROM			1U		/* 程序运行环境为APROM下运行 */
#define   RUNNING_ENV_LDROM			2U		/* 程序运行环境为LDROM下运行 */
#define   MCU_TYPE				 	BSP_MCU_TYPE

#define DEFAULT_APP 				0	//默认启动APP
#define APP_WITHOUT_BOOT			1	//默认启动BOOT但BOOT需要单独烧写
#define APP_AND_BOOT				2	//默认启动BOOT工程中包括BOOT镜像
#define APP_VECT_TAB_OFFSET			0x4000	//16K用于bootload

#define COMPILE_MODE 				APP_AND_BOOT	//定义编译模式


#if	TEST_UPDATE_OUT == 1
	#undef	PROGRAM_VER_MODIFY						
	#define PROGRAM_VER_MODIFY		1	/* 重定义版本号最低位PROGRAM_VER_MODIFY */

	#undef	USERPRINTF
	#define USERPRINTF			printf	
#endif
#define	DEVICE_ID_SIZE			4
//------------GPIO---------------
#define PC14		GPIOC,GPIO_PIN_14		//PC14
#define PC15		GPIOC,GPIO_PIN_15		//PC15

#define SSADC1		GPIOA,GPIO_PIN_0		//PA0	
#define SSADC2		GPIOA,GPIO_PIN_1		//PA1
#define UART0_TX	GPIOA,GPIO_PIN_2		//PA2	
#define UART0_RX	GPIOA,GPIO_PIN_3		//PA3
#define MCU_LED		GPIOA,GPIO_PIN_4		//PA4
#define SCK			GPIOA,GPIO_PIN_5		//PA5
#define MISO		GPIOA,GPIO_PIN_6		//PA6
#define MOSI		GPIOA,GPIO_PIN_7		//PA7	

#define SOC_RST		GPIOB,GPIO_PIN_0		//PB0
#define RST_EN		GPIOB,GPIO_PIN_1		//PB1
#define RELAY1		GPIOB,GPIO_PIN_2		//PB2
#define PB10		GPIOB,GPIO_PIN_10		//PB10	
#define PB11		GPIOB,GPIO_PIN_11		//PB11

#define SW1			GPIOB,GPIO_PIN_12		//PB12
#define SW2			GPIOB,GPIO_PIN_13		//PB13
#define SW3			GPIOB,GPIO_PIN_14		//PB14
#define SW4			GPIOB,GPIO_PIN_15		//PB15

#define SW7			GPIOA,GPIO_PIN_8		//PA8
#define ADC_LED1	GPIOA,GPIO_PIN_9		//PA9
#define ADC_LED2	GPIOA,GPIO_PIN_10		//PA10
#define BUZZ		GPIOA,GPIO_PIN_11		//PA11	
#define SW8			GPIOA,GPIO_PIN_12		//PA12
#define SWDIO		GPIOA,GPIO_PIN_13		//PA13
#define SCL2		GPIOF,GPIO_PIN_6		//PF6
#define SDA2		GPIOF,GPIO_PIN_7		//PF7

#define SWCLK		GPIOA,GPIO_PIN_14		//PA14 
#define INT_OUT		GPIOA,GPIO_PIN_15		//PA15
#define RELAY2		GPIOB,GPIO_PIN_3		//PB3
#define RELAY3		GPIOB,GPIO_PIN_4		//PB4
#define RELAY4		GPIOB,GPIO_PIN_5		//PB5
#define UART1_TX	GPIOB,GPIO_PIN_6		//PB6
#define UART1_RX	GPIOB,GPIO_PIN_7		//PB7
#define SW5			GPIOB,GPIO_PIN_8		//PB8
#define SW6			GPIOB,GPIO_PIN_9		//PB9


#define SOC_RST_START	0	//复位输出
#define RST_EN_START	1	

#define SOC_RST_STOP	1	//复位禁止
#define RST_EN_STOP		0

#define RELAY_TYPE_NO	0	//常开型继电器
#define RELAY_TYPE_NC	1	//常闭型继电器

#define RELAY_CLOSE		1	//吸合
#define RELAY_OPEN		0	//断开

//------------GPIO操作函数定义---------------
#define LED_ON()					gpio_bit_write(MCU_LED,1)
#define LED_OFF()					gpio_bit_write(MCU_LED,0)
#define LED_TOGGLE()    			gpio_bit_toggle(MCU_LED)

#define LED1_ON()					gpio_bit_write(ADC_LED1,0)
#define LED1_OFF()					gpio_bit_write(ADC_LED1,1)
#define LED1_TOGGLE()    			gpio_bit_toggle(ADC_LED1)

#define LED2_ON()					gpio_bit_write(ADC_LED2,0)
#define LED2_OFF()					gpio_bit_write(ADC_LED2,1)
#define LED2_TOGGLE()    			gpio_bit_toggle(ADC_LED2)

#define RESET_PMU_START() 			gpio_bit_write(SOC_RST,0);gpio_bit_write(RST_EN,1)//RESET_PMU = 0,POWER_PMU_ENABLE = 1	
#define RESET_PMU_STOP()			gpio_bit_write(SOC_RST,1);gpio_bit_write(RST_EN,0)//RESET_PMU = 1,POWER_PMU_ENABLE = 0

#define RELAYx_OPEN(x)				gpio_bit_write(x,RELAY_OPEN)
#define RELAYx_CLOSE(x)				gpio_bit_write(x,RELAY_CLOSE)
#define RELAYx_GET(x)				gpio_output_bit_get(x)
#define RELAYx_SET(x,y)				gpio_bit_write(x,y)


//----------------FLASH分配-------------------------------------
#define FLASH_BASE_ADDR 		FLASH_BASE	//0x08000000u
#define FLASH_SIZE				0x10000
#define FLASH_END_ADDR 			(FLASH_BASE + FLASH_SIZE)

#define BOOTLOAD_BASE_ADDR 		FLASH_BASE_ADDR	
#define BOOTLOAD_SIZE			0x4000
#define BOOTLOAD_END_ADDR 		(BOOTLOAD_BASE_ADDR + BOOTLOAD_SIZE)

#define USER_DATA_SIZE			FMC_PAGE_SIZE
#define USER_DATA_ADDR			(uint32_t)(FLASH_END_ADDR - BOOTLOAD_SIZE)	//密码存储位置

#define APP_FLASH_BASE     	 	BOOTLOAD_END_ADDR
#define	APP_FLASH_SIZE		 	(FLASH_SIZE - BOOTLOAD_BASE_ADDR - USER_DATA_SIZE)	
#define APP_FLASH_END        	(APP_FLASH_BASE + APP_FLASH_SIZE)


#define GET_ADC_TIME	5

#define LED_PERIOD		15
//定义常用标识
/*  返回状态定义 */
#define SUCCESS 	true 		
#define FAIL    	false

#define ENABLE		1
#define DISABLE		0

#define BUSY		0x01
#define TIMEOUT		0x02

#define WRITE		0x00
#define READ		0x01




//#define buzzerStart(x,y)


#endif	/* __CONFIG_H_ */


